import colorsys
import os
import random

import cv2
import numpy as np


def get_n_hls_colors(num):
    hls_colors = []
    i = 0
    step = 360.0 / num
    while i < 360:
        h = i
        s = 90 + random.random() * 10
        l = 50 + random.random() * 10
        _hlsc = [h / 360.0, l / 100.0, s / 100.0]
        hls_colors.append(_hlsc)
        i += step
 
    return hls_colors
 
def ncolors(num):
    rgb_colors = []
    if num < 1:
        return rgb_colors
    hls_colors = get_n_hls_colors(num)
    for hlsc in hls_colors:
        _r, _g, _b = colorsys.hls_to_rgb(hlsc[0], hlsc[1], hlsc[2])
        r, g, b = [int(x * 255.0) for x in (_r, _g, _b)]
        rgb_colors.append([r, g, b])
 
    return rgb_colors


if __name__ == "__main__":
    image = np.zeros([100, 100, 3])
    colors = ncolors(10)
    random.shuffle(colors)
    for i in range(10):
        for j in range(100):
            for k in range(10):
                image[j][i*10+k] = colors[i]
    cv2.imwrite("colors.png", image)
